grammar Process;
@lexer::header
{
package antlrpack;
}
@header
{
package antlrpack;
import model.Location;
import model.UserData;
import org.hibernate.Session;
import org.hibernate.Transaction;
import hibernate.util.SessionFactoryUtil;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
}
@members
{
public Session session;
public ProcessParser(TokenStream input,int id)
{
this(input);
session = SessionFactoryUtil.getSessionFactory().openSession();
}
}

prog	:	alt;
//stat	:	(ID|INT)* time (ID|INT)*{System.out.println($time.value1+"."+$time.value2);};




alt	:	a=time (others)* traffic prep b=ID (others|ID)* normal prep d=time(others|ID|NEWLINE)*{System.out.println(a.value1+"."+a.value2);
System.out.println(":"+$b.text); System.out.println($d.value1+"."+$d.value2);

Transaction tx = session.beginTransaction();

GregorianCalendar cal = new GregorianCalendar();
cal.set(Calendar.HOUR, $a.value1);
  cal.set(Calendar.MINUTE,$a.value2);
Date cur=cal.getTime();
UserData data=new UserData();
data.setUserTime(cur);
session.save(data);
tx.commit();
}|
(ID|others)* traffic prep e=ID (ID|others)* time (ID|others)*{System.out.println($time.value1+"."+$time.value2+$e.text);};


traffic returns [String args]:TRAFFIC|TRAFFIC BLOCK;

//revival	:	normal ID time|normal ID duration;

normal	:	'ok'|'normal'|'smooth';
duration returns [int dur]	:	INT MIN{$dur=Integer.parseInt($INT.text);}|INT HRS;

prep	:	'at'|'in'|'by';
others	:	prep|COLON|DOT;





time returns [int value1,int value2]:timedef{$value1=$timedef.value1;   $value2=$timedef.value2;} |
timedef AM{$value1=$timedef.value1;   $value2=$timedef.value2;}|
timedef PM{
$value1=($timedef.value1+12); 
  $value2=$timedef.value2;};


timedef returns [int value1,int value2]	:	TIME{$value1=Integer.parseInt($TIME.text);}|
TIME DOT FRACT{$value1=Integer.parseInt($TIME.text);
$value2=Integer.parseInt($FRACT.text);}|a=TIME DOT b= TIME{$value1=Integer.parseInt($a.text);
$value2=Integer.parseInt($b.text);};
COLON	:	':';

MIN	:	'minutes'|'minute'|'min'|'mins';
HRS	:	'hour'|'hours'|'hr'|'hrs';
BLOCK	:	'block'|'jam'|'blk'|'blck';
TRAFFIC	:	'traffic'|'accident'|'trafic'|'trfic'|'trafik'|'accdnt';
AM	:	'AM'|'am';
PM	:	'PM'|'pm';
DOT	:	'.';
ID  :   ('a'..'z'|'A'..'Z')+ ;
TIME	:	'10'|'11'|'12'|'13'|'14'|'15'|'16'|'17'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'18'|'19'|'20'|'21'|'22'|'23';
FRACT	:	('0'..'5')('0'..'9');
TA	: ('0'..'9');
INT :   '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS  :   (' '|'\t'|'\n'|'\r')+ {skip();} ;